﻿CREATE PROCEDURE [ProductImage].[GetProductImages]
	@TenantId uniqueidentifier,
	@CatalogId TCatalogId,
	@ProductId TProductId
AS

-- 1st
SELECT
	[PI].ImageId,
	[PI].ViewId,
	[PI].DefaultAlternativeText,
	[PI].DefaultUsagePermissionText
FROM
	ProductImage [PI]
WHERE
	[PI].TenantId = @TenantId
	AND [PI].CatalogId = @CatalogId
	AND [PI].ProductId = @ProductId

-- 2nd
SELECT
	[PI].ImageId,
	PIL.CultureId,
	PIL.AlternativeText,
	PIL.UsagePermissionText
FROM
	ProductImage [PI]
	LEFT OUTER JOIN ProductImageLocalization PIL ON [PI].TenantId = PIL.TenantId AND [PI].ImageId = PIL.ImageId
WHERE
	[PI].TenantId = @TenantId
	AND [PI].CatalogId = @CatalogId
	AND [PI].ProductId = @ProductId

-- 3rd
SELECT
	[PI].ImageId,
	PIV.SizeId,
	PIV.Path
FROM
	ProductImage [PI]
	INNER JOIN ProductImageVariant PIV ON [PI].TenantId = PIV.TenantId AND [PI].ImageId = PIV.ImageId
WHERE
	[PI].TenantId = @TenantId
	AND [PI].CatalogId = @CatalogId
	AND [PI].ProductId = @ProductId
